// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
import App from "./App";
import router from "./router";
//项目依赖的基础样式-----------------------------------------------
import "./assets/css/base.css"; //基础样式
import "mint-ui/lib/style.css"; //mint-ui CSS 库
//项目依赖的基础样式-----------------------------------------------
//项目依赖的mintJs组件库-----------------------------------------------
import MintUI from "mint-ui";
Vue.use(MintUI);
// Vue.component(Toast, Toast)
//项目依赖的mintJs组件库-----------------------------------------------
//项目依赖的Vues状态控制-----------------------------------------------
import store from "./vuex/store";
import Vuex from "vuex";
Vue.use(Vuex);
//项目依赖的Vues状态控制-----------------------------------------------
//项目依赖的Vues状态控制-----------------------------------------------
import Viewer from "c-v-viewer";
console.log(Viewer);
Vue.use(Viewer);
Viewer.setDefaults({
  inline: true,
  button: false,
  navbar: false,
  title: false,
  toolbar: false,
  tooltip: true,
  movable: true,
  zoomable: true,
  rotatable: true,
  scalable: true,
  transition: true,
  fullscreen: false,
  keyboard: false
});
//项目依赖的Vues状态控制-----------------------------------------------
// //项目插件Swiper-----------------------------------------------
// import Swiper from 'vue-awesome-swiper';
// import 'swiper/dist/css/swiper.min.css';
// Vue.use(Swiper);
// //项目插件Swiper-----------------------------------------------
Vue.config.productionTip = false;
//动态设置html的字体大小----------------------勿动-------------------------
new function() {
  var _self = this;
  _self.width = 750; //����Ĭ�������
  _self.fontSize = 100; //Ĭ�������С
  _self.widthProportion = function() {
    var p =
      ((document.body && document.body.clientWidth) ||
        document.getElementsByTagName("html")[0].offsetWidth) / _self.width;
    return p > 1 ? 1 : p < 0.43 ? 0.43 : p;
  };
  _self.changePage = function() {
    document
      .getElementsByTagName("html")[0]
      .setAttribute(
        "style",
        "font-size:" +
          _self.widthProportion() * _self.fontSize +
          "px !important"
      );
  };
  _self.changePage();
  window.addEventListener(
    "resize",
    function() {
      _self.changePage();
    },
    false
  );
}();
//动态设置html的字体大小----------------------勿动-------------------------
//定义一个VUE内全局用到的名称（标题）
Vue.prototype.appName = "电子胶片";
//添加路由钩子修改每个页面标题
router.beforeEach((to, form, next) => {
  // console.log(to);
  // console.log(form);
  if (store.state.canLink) {
    if (form.name == "UserFilmDetail") {
      window.location.hash = form.fullPath;
      return;
    }
  }

  window.document.title = Vue.prototype.appName;
  //如果自定义了标题就取标题，否则拿全局标题
  // window.document.title = to.meta.title !== undefined ? (to.meta.title + '-' + Vue.prototype.appName) : Vue.prototype.appName;
  next();
});

//通过components下的index.js文件导入组件
import components from "./components/index";
//对导入的组件进行全局组件注册
Object.keys(components).forEach(key => {
  Vue.component(key, components[key]);
});
/* eslint-disable no-new */

//通过判断设备进行路由重定向
import { isDeviceSelect } from "./utils/index";
var selectChoose = isDeviceSelect();
var urlParams = (function(href) {
  var url = "?" + href.split("?")[1];
  url = url.split("#")[0];
  var thisParam = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    var strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      thisParam[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }
  return thisParam;
})(
  'http://182.168.5.87:8080/#/userFilmDetail?patientid=T001502561&studyid=T001502561&hospcode=ZL2018YX&hospdomain=ZL2018'
);

// window.location.href
// 'http://182.168.5.87:8080/#/userFilmDetail?patientid=1205110201&studyid=120601001&hospcode=1030001&hospdomain=1030001'

var params =
  "/" +
  urlParams.studyid +
  "/" +
  urlParams.hospcode +
  "/" +
  urlParams.patientid +
  "/" +
  urlParams.hospdomain;

if (selectChoose == "phone") {
  router.push("userFilmDetail" + params);
} else if (selectChoose == "pad") {
  router.push("userDetail" + params);

  // var detectOrient = function () {
  //   var width = document.documentElement.clientWidth;
  //   var height = document.documentElement.clientHeight;
  //   var wrapper = document.getElementById("app");
  //   var style = "";
  //   if (width >= height) { // 竖屏
  //     style += "width:100%";
  //     style += "height:100%;";
  //     style += "-webkit-transform: rotate(0); transform: rotate(0);";
  //     style += "-webkit-transform-origin: 0 0;";
  //     style += "transform-origin: 0 0;";
  //   } else { // 横屏
  //     style += "width:" + height + "px;"; // 注意旋转后的宽高切换
  //     style += "height:" + width + "px;";
  //     style += "-webkit-transform: rotate(90deg); transform: rotate(90deg);";
  //     // 注意旋转中点的处理
  //     style += "-webkit-transform-origin: " + width / 2 + "px " + width / 2 + "px;";
  //     style += "transform-origin: " + width / 2 + "px " + width / 2 + "px;";
  //   }
  //   wrapper.style.cssText = style;
  // }
  // detectOrient();
  // window.onresize = detectOrient;
} else if (selectChoose == "pc") {
  var url = window.location.protocol + "//" + window.location.hostname + ":8088";
  window.location.assign(url);
}
new Vue({
  el: "#app",
  router,
  store,
  components: {
    App
  },
  template: "<App/>"
});
